package com.wangx.service.impl;

import com.wangx.dao.UserDao;
import com.wangx.entity.User;
import com.wangx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void register(User user) {
        User nameDB = userDao.findByName(user.getName());
        if (nameDB != null) {
            throw new RuntimeException("当前用户名已被注册，请修改后再试！！！");
        }
        user.setRegtime(new Date());
        user.setStatus("激活");
        userDao.saveUser(user);

    }
}
